package com.gz.mylife.app;

import java.util.ArrayList;
import java.util.List;

import com.gz.mylife.Define;
import com.gz.mylife.R;
import com.gz.mylife.adapter.BaseAdapterHelper;
import com.gz.mylife.adapter.QuickAdapter;
import com.gz.mylife.util.ImageUtils;
import com.gz.mylife.widget.LoadingCover;
import com.gz.mylife.widget.LoadingCover.OnLoadingCoverRefreshListener;
import com.gz.mylife.widget.OfflineDialog;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.zl.smartmall.library.ISmartMall;
import com.zl.smartmall.library.listener.ShopsIntroduceListener;
import com.zl.smartmall.library.po.ShopsIntroduce;
import android.os.Bundle;
import android.widget.GridView;

public class ShopIntroductActivity extends BaseActivity implements OnLoadingCoverRefreshListener {
	private QuickAdapter<ShopsIntroduce> shopAdapter1;
	private QuickAdapter<ShopsIntroduce> shopAdapter2;
	private QuickAdapter<ShopsIntroduce> shopAdapter3;
	private LoadingCover mLoadingCover;
	private OfflineDialog mOfflineDialog;
	private DisplayImageOptions mIconOptions;
	private GridView gridview_classify1;
	private GridView gridview_classify2;
	private GridView gridview_classify3;
	private ShopsIntroduceListener shoplistener;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_shopintroduce);
		setActionbarTitle("商家介绍", false);
		buildListener();
		onLoadingAdvertise();
		gridview_classify1 = (GridView)findViewById(R.id.gridview_classify1);
		gridview_classify2 = (GridView)findViewById(R.id.gridview_classify2);
		gridview_classify3 = (GridView)findViewById(R.id.gridview_classify3);
		mLoadingCover = (LoadingCover) findViewById(R.id.layout_loading_cover);
		mLoadingCover.setOnLoadingCoverRefreshListener(this);
		mOfflineDialog = (OfflineDialog) getLayoutInflater().inflate(R.layout.offline_dialog, null);
		mIconOptions = ImageUtils.buildTransparentOptions();
		shopAdapter1 = buildRecommendMerchantAdater1();
		shopAdapter2 = buildRecommendMerchantAdater1();
		shopAdapter3 = buildRecommendMerchantAdater1();
		gridview_classify1.setAdapter(shopAdapter1);
		gridview_classify2.setAdapter(shopAdapter2);
		gridview_classify3.setAdapter(shopAdapter3);
		
	}
	private QuickAdapter<ShopsIntroduce> buildRecommendMerchantAdater1(){
		return new QuickAdapter<ShopsIntroduce>(this, R.layout.fragment_mall_merchant_item, new ArrayList<ShopsIntroduce>()) {
			
			@Override
			protected void convert(BaseAdapterHelper helper, ShopsIntroduce item) {
				
					helper.setImageUrl(R.id.iv_picture, item.getPic(), mIconOptions);
					helper.setText(R.id.tv_name, item.getName());
			}
		};
	}
	
	
	private void buildListener() {
		shoplistener =  new ShopsIntroduceListener() {

			@Override
			public void onResponseSuccess(List<ShopsIntroduce> shopinfo1,List<ShopsIntroduce> shopinfo2,List<ShopsIntroduce> shopinfo3) {
				// TODO Auto-generated method stub
				shopAdapter1.addAll(shopinfo1);
				shopAdapter2.addAll(shopinfo2);
				shopAdapter3.addAll(shopinfo3);
				mLoadingCover.onRefreshSuccess();
			}

			@Override
			public void onNoMoreData() {
				// TODO Auto-generated method stub
				
			}

			@Override
			public void onNoNetWork() {
				// TODO Auto-generated method stub
				mLoadingCover.onRefreshFailed(Define.MSG_NO_NETWORK);
			}

			@Override
			public void onOffline() {
				// TODO Auto-generated method stub
				mLoadingCover.onRefreshFailed();
				mOfflineDialog.show();
				mLoadingCover.onRefreshFailed(Define.MSG_OFFLINE_ERROR);
			}

			@Override
			public void onResponseFailed() {
				// TODO Auto-generated method stub
				
			}

			
		};
	}
	@Override
	public void onLoadingCoverRefresh() {
		// TODO Auto-generated method stub
	}
	public void onLoadingAdvertise() {
		// TODO Auto-generated method stub
		ISmartMall.getInstance().get_join_pic(shoplistener);
	}
	
}
